package listbyorder.access201_300.test287;

/**
 * 好题
 * @author code_yc
 * @version 1.0
 * @date 2020/6/28 14:33
 */
// 双指针找到入环节点(链表的数组变形)
public class Solution3 {

    public int findDuplicate(int[] nums) {
        int n = nums.length;
        int a = nums[0];
        int b = nums[nums[0]];
        while (a != b) {
            a = nums[a];
            b = nums[nums[b]];
        }
        a = 0;
        while (a != b) {
            a = nums[a];
            b = nums[b];
        }
        return a;
    }
}
